package app.service.loader
{
	

	import app.model.global.ApplicationModel;

	import flash.events.*;
	import flash.net.*;
	import flash.utils.describeType;
	
	import org.robotlegs.mvcs.Actor;
	
	public class BaseURLLoaderService extends Actor implements URLLoaderServiceInterface
	{

		[Inject]
		public var appModel:ApplicationModel;
		
		protected var functionCalled:String;
		
		public function loadURL(url:String):void
		{
			var loader:URLLoader = new URLLoader();
			configureListeners(loader);
			
			var request:URLRequest = new URLRequest(url);
			try {
				loader.load(request);
			} catch (error:Error) {
				trace("Unable to load requested document.");
			}
		}
		
		
		
		protected function configureListeners(disp:IEventDispatcher):void {
			disp.addEventListener(Event.COMPLETE, completeHandler);
			disp.addEventListener(Event.OPEN, openHandler);
			disp.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			disp.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
			disp.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
			disp.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}
		
		protected function completeHandler(event:Event):void {
			var loader:URLLoader = URLLoader(event.target);
			//trace("BaseURLLoaderService completeHandler: " + loader.data);
		}
		
		protected function openHandler(event:Event):void 
		{
			trace("BaseURLLoaderService openHandler: " + event);
		}
		
		protected function progressHandler(event:ProgressEvent):void {
			trace("BaseURLLoaderService progressHandler: " + event);
		}
		
		protected function securityErrorHandler(event:SecurityErrorEvent):void {
			trace("BaseURLLoaderService securityErrorHandler: " + event);
		}
		
		protected function httpStatusHandler(event:HTTPStatusEvent):void {
			trace("BaseURLLoaderService httpStatusHandler: " + event);
		}
		
		protected function ioErrorHandler(event:IOErrorEvent):void {
			trace("BaseURLLoaderService ioErrorHandler: " + event);
		}
	}
}